import { AxiosPromise } from 'axios';
import { AccountQuery, getWechatInfoVO, updateWechatAppVO, AccountVO, WechatQuery, TypeMicroWechatVO } from './types';
import request from '@/utils/request';

/**
 * 查询微信小程序列表
 */
export const listWechatApp = (query: WechatQuery): AxiosPromise<AccountVO[]> => {
  return request({
    url: '/oce/microWechatApp/list',
    method: 'get',
    params: query
  });
};

export const listAccount = (query: AccountQuery): AxiosPromise<AccountVO[]> => {
  return request({
    url: '/system/account/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询账户详细
 */
export const getAccount = (roleId: string | number): AxiosPromise<AccountVO> => {
  return request({
    url: '/system/account/' + roleId,
    method: 'get'
  });
};

/**
 * 新增账户
 */
export const addAccount = (data: any) => {
  return request({
    url: '/system/account',
    method: 'post',
    data: data
  });
};

/**
 * 修改账户
 * @param data
 */
export const updateAccount = (data: any) => {
  return request({
    url: '/system/account',
    method: 'put',
    data: data
  });
};

/**
 * 账户状态修改
 */
export const changeRoleStatus = (roleId: string | number, status: string) => {
  const data = {
    roleId,
    status
  };
  return request({
    url: '/system/role/changeStatus',
    method: 'put',
    data: data
  });
};

/**
 * 删除管理账户
 */
export const delAccount = (accountRecordIds: Array<string | number> | string | number) => {
  return request({
    url: '/system/account/' + accountRecordIds,
    method: 'delete'
  });
};

/**
 * 创建微信小程序
 */
export const createWechatApp = (data: TypeMicroWechatVO) => {
  return request({
    url: '/oce/third/createToolsWechatApplet',
    method: 'post',
    data: data
  });
};

//获取微信小程序
export const getWechatAppInfo = (query: getWechatInfoVO) => {
  return request({
    url: '/oce/third/queryWechatApplet',
    method: 'get',
    params: query
  });
};

//更新微信小程序
export const updateWechatApp = (data: updateWechatAppVO) => {
  return request({
    url: '/oce/third/updateToolsWechatApplet',
    method: 'post',
    data: data
  });
};
